<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Messenger/classes/PhpFox_ComponentReport.class.php, $Author:  $ */



/** Report component
 * 
 * @package module.messenger
 * @version $Id: PhpFox_ComponentReport.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *   PHPFox Team ()
 */
class PhpFox_Mod_Messenger_ComponentReport extends BaseComponent
{
    /** Processing method
     */
	function process()
	{
	    $oReq = &App::getRequest();
	    $oSrvAcc = &App::getModuleService('Account', 'Security');
        $oCurrUser = &$oSrvAcc->getCurrentUser();
	    $sReportUser = $oReq->get('user');
	    
	    if(empty($sReportUser) || null == $oSrvAcc->getUserByName($sReportUser))
	        App::gotoBackUrl('public.account');

	    $oRepUser = $oSrvAcc->getUserByName($sReportUser);
	    if ($oRepUser->aData['friends_only'])
        {
            $oSrvFriend = App::getModuleService('Account', 'Friends');
            /* @var $oSrvFriend PhpFox_Mod_Account_ServiceFriends */
            $bIsBlocked = !$oSrvFriend->isFriend($oRepUser, $oCurrUser);
            if($bIsBlocked)
                App::gotoUrl('public.user.blocked', array('name'=>$sReportUser));
        }

	    $oSrvMessenger = &$this->_oModule->getService('Messenger');
        $aPost = $oReq->getArray('aReport');
        
        if(!empty($aPost['user']))
        {
            if(empty($aPost['text']))
                $this->addErrors(App::format('Mod_messenger.text.error'));
            if(strtolower($sReportUser) == strtolower($oCurrUser->aData['user']))
                $this->addErrors(App::format('Mod_messenger.report.owner'));
            $aErrors = $this->getErrors();
            if(empty($aErrors))
            {
                $oSrvMessenger->sendReport($aPost, $oCurrUser->aData['user']);
                App::gotoUrl('', array('user'=>$sReportUser), array(App::format('Mod_messenger.report.completed', array($sReportUser))), false, 'Report');
            }
            else 
                $aReport = $aPost;
        }
        
        $oTpl = &$this->_oModule->getTemplate();
        $oTpl->assignSrc(array(
                                'aErrors'	  => $this->getErrors(),
                                'sImageUrl'   => App::getParam('user.pic.url'),
                                'aReport'     => (empty($aReport)) ? false : $aReport,
                                'sReportUser' => $sReportUser,
		                ));
		$srcHtml = $oTpl->fetch('Report.html');
		return $srcHtml;
	}
}
?>